# Maintainer: Kyle Keen <keenerd@gmail.com>
# Contributor: Dominik Heidler <dheidler@gmail.com>

_name=gr-iqbal
pkgname=gnuradio-iqbal
pkgver=0.38.2.r9.gfbee239
_commit=fbee239a6fb36dd2fb564f6e6a0d393c4bc844db
pkgrel=3
pkgdesc="Gnuradio I/Q balancing"
arch=(loong64 x86_64)
url="https://cgit.osmocom.org/gr-iqbal/"
license=(GPL3)
depends=(
  gcc-libs
  glibc
  python
  # python-pygccxml  # TODO: package
)
provides=(libgnuradio-iqbalance.so)
replaces=(gr-iqbal)
makedepends=(boost cmake fftw gnuradio git gmp libvolk pybind11)
source=(
  git+https://gitea.osmocom.org/sdr/gr-iqbal.git#commit=$_commit
  git+https://gitea.osmocom.org/sdr/libosmo-dsp.git  # TODO: package this instead
)
sha256sums=('SKIP'
            'SKIP')

pkgver() {
  cd $_name
  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//g'
}

prepare() {
  cd $_name

  git submodule init
  git submodule set-url libosmo-dsp "$srcdir/libosmo-dsp"
  git -c protocol.file.allow=always submodule update
}

build() {
  local cmake_options=(
    -B build
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_LIBRARY_PATH=/usr/lib
    -S $_name
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build
}

package() {
  depends+=(
    fftw libfftw3f.so
    gnuradio libgnuradio-pmt.so libgnuradio-runtime.so
  )

  DESTDIR="$pkgdir" cmake --install build
}
